﻿using GalaSoft.MvvmLight.Command;
using HuiZe.education.Model;
using HuiZe.education.Resource.Controls;
using HuiZe.education.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace HuiZe.education.View
{
    /// <summary>
    /// GroupView.xaml 的交互逻辑
    /// </summary>
    public partial class GroupView : HuiZeWindow
    {
        public MySpaceViewModel mySpaceViewModel { get; set; }
        public GroupView()
        {
            InitializeComponent();
            this.MaxHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height + 10;
            this.MaxWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width + 10;
            Loaded += LoginView_Loaded;
        }

        private void LoginView_Loaded(object sender, RoutedEventArgs e)
        {
            //ImgGrid.Width = this.Width - 300;
            //ImgGrid.Height = this.Height - 200;

            mySpaceViewModel = DataContext as MySpaceViewModel;
            //MySpaceViewModel ResourceViewModel = DataContext as MySpaceViewModel;
            mySpaceViewModel.GetGroupList(1);
            pageManage.ItemSourceCount = mySpaceViewModel.pageCount2;
            mySpaceViewModel.groupView = this;



        }

        public bool ShowDialogView(string content)
        {
            ShowDialogView showDialogView = new ShowDialogView() { ShowDialogContent = content };
            if (showDialogView.ShowDialog() == true)
            {
                return true;

            }
            else
            {
                return false;

            }
        }
        private void YCButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MySpaceViewModel mySpaceViewModel = DataContext as MySpaceViewModel;
            var model = mySpaceViewModel.SelectedGroupModel;
            Button btn = sender as Button;
            switch (btn.Name)
            {
                case "modify":
                    break;
                case "dele":
                    mySpaceViewModel.MyGroups.Remove(model);
                    break;

            }
        }
        private void YCButton_Click1(object sender, System.Windows.RoutedEventArgs e)
        {
            MySpaceViewModel mySpaceViewModel = DataContext as MySpaceViewModel;

            if (dg_group.SelectedItem != null)
            {
                GroupModel group = (GroupModel)dg_group.SelectedItem;
                int Id = group.Id;//获取选中行的name列内容
                string groupName = group.GroupName;

                //MessageBoxResult result = MessageBox.Show("确定要删除学生"+ studentName + "？", "提示", MessageBoxButton.YesNo);//弹出删除对话框

                bool result = ShowDialogView("确定要删除分组" + groupName + "？");
                switch (result)
                {
                    case true:
                        mySpaceViewModel.delGroup(Id); ;//调用函数，删除数据库
                        //DRV.Delete();//删除行
                        //MessageBox.Show("删除成功！");
                        break;
                    case false:
                        break;
                }
            }
        }

        private void modify_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MySpaceViewModel mySpaceViewModel = DataContext as MySpaceViewModel;
            if (dg_group.SelectedItem != null)
            {
                GroupModel group = (GroupModel)dg_group.SelectedItem;
                EditGroupView editGroupView = new EditGroupView() { DataContext = mySpaceViewModel };
                editGroupView.groupId = group.Id;
                editGroupView.groupName = group.GroupName;
                editGroupView.mySpaceViewModel = mySpaceViewModel;
                editGroupView.ShowDialog();
            }
        }

        //GetGroupList()

        private void PageManage_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource.ToString().Contains("CustomRadioButton"))
            {
                CustomRadioButton button = e.OriginalSource as CustomRadioButton;
                string index = button.Content.ToString();
                if (index == ">")
                {
                    //index = pageManage.Content.ToString();
                    index = pageManage.CurrentIndex < pageManage.ItemSourceCount ? (pageManage.CurrentIndex + 1).ToString() : pageManage.CurrentIndex.ToString();
                }
                if (index == "<")
                {
                    index = pageManage.CurrentIndex > 1 ? (pageManage.CurrentIndex - 1).ToString() : "1";
                }
                if (index == "首页")
                {
                    index = "1";
                }
                if (index == "尾页")
                {
                    index = pageManage.ItemSourceCount.ToString();
                }
                mySpaceViewModel.GetGroupList(Convert.ToInt32(index));
            }
        }

        public void UpdataPageManage()
        {

            pageManage.ItemSourceCount = mySpaceViewModel.pageCount2;


        }
    }
}
